<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Antibioticos
 *
 * @author amartinez
 */
class Antibioticos {
    private $oidAntibiotico;
    private $cantDias;
    private $cantDosis;
    private $canTiempo;
    private $usuario;
    private $primFecha;
    private $fechaRegis;
    private $paciente;
    
    function __construct($oidAntibiotico, $cantDias, $cantDosis, $canTiempo, $usuario, $primFecha, $fechaRegis, $paciente) {
        $this->oidAntibiotico = $oidAntibiotico;
        $this->cantDias = $cantDias;
        $this->cantDosis = $cantDosis;
        $this->canTiempo = $canTiempo;
        $this->usuario = $usuario;
        $this->primFecha = $primFecha;
        $this->fechaRegis = $fechaRegis;
        $this->paciente = $paciente;
    }
    
    public function getoidAntibiotico(){
        return $this->oidAntibiotico;
    }
    public function setoidAntibiotico($oidAntibiotico){
        $this->oidAntibiotico = $oidAntibiotico;
    }
    public function getcantDias(){
        return $this->cantDias;
    }
    public function setcantDias($cantDias){
        $this->cantDias = $cantDias;
    }
    public function getcantDosis(){
        return $this->cantDosis;
    }
    public function setcantDosis($cantDosis){
        $this->cantDosis = $cantDosis;
    }
    public function getcanTiempo(){
        return $this->canTiempo;
    }
    public function setcanTiempo($canTiempo){
        $this->canTiempo = $canTiempo;
    }
    public function getusuario(){
        return $this->usuario;
    }
    public function setusuario($usuario){
        $this->usuario = $usuario;
    }
    public function getprimFecha(){
        return $this->primFecha;
    }
    public function setprimFecha($primFecha){
        $this->primFecha = $primFecha;
    }
    public function getfechaRegis(){
        return $this->fechaRegis;
    }
    public function setfechaRegis($fechaRegis){
        $this->fechaRegis = $fechaRegis;
    }
    public function getpaciente(){
        return $this->paciente;
    }
    public function setpaciente($paciente){
        $this->paciente = $paciente;
    }
    
    function Antibiotico($paciente,$ingre){
        include '../../../controlador/php/conexion/Conexion10.php';
        $con = new Conexion10();
        
        $select = "SELECT entantibio.oid as oidentantibio,INNPRODUC.OID, IPRCODIGO, IPRDESCOR, PACNUMDOC, AINCONSEC, (PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE) AS NOMBRES,
                    antcantdias,antdosican,antdositie,antfecprim,antfecreg
                    FROM INNMSUMPA 
                    LEFT JOIN INNCSUMPA ON INNCSUMPA.OID = INNMSUMPA.INNCSUMPA 
                    LEFT JOIN INNDOCUME ON INNDOCUME.OID = INNCSUMPA.OID 
                    LEFT JOIN INNMDESUM ON INNMDESUM.INNMSUMPA = INNMSUMPA.OID
                    LEFT JOIN INNCDESUM ON INNCDESUM.OID = INNMDESUM.INNCDESUM
                    LEFT JOIN INNDOCUME AS B ON B.OID = INNCDESUM.OID 
                    LEFT JOIN INNPRODUC ON INNPRODUC.OID = INNMSUMPA.INNPRODUC OR INNPRODUC.OID = INNMDESUM.INNPRODUC
                    LEFT JOIN ADNINGRESO ON ADNINGRESO.OID = INNCSUMPA.ADNINGRESO 
                    LEFT JOIN GENPACIEN ON GENPACIEN.OID = ADNINGRESO.GENPACIEN 
                    LEFT JOIN planillaUsuario..entantibio ON INNPRODUC.OID = entantibio.innproduc and PACNUMDOC = paciente
                    WHERE
                    (
                       IPRDESCOR LIKE '%CEFTRIAXONA%' 
                    OR IPRDESCOR LIKE '%CEFOTAXIMA%' 
                    OR IPRDESCOR LIKE '%CEFEPIM%'
                    OR IPRDESCOR LIKE '%CIPROFLOXACINA%'
                    OR IPRDESCOR LIKE '%CLARITROMICINA%'
                    OR IPRDESCOR LIKE '%IMIPENE%'
                    OR IPRDESCOR LIKE '%MEROPENEM%'
                    OR IPRDESCOR LIKE '%DORIPENEM%'
                    OR IPRDESCOR LIKE '%ERTAPENE%'
                    OR IPRDESCOR LIKE '%PIPERACILINA%'
                    OR IPRDESCOR LIKE '%TAZOBACTAM%'
                    OR IPRDESCOR LIKE '%VANCOMICINA%'
                    OR IPRDESCOR LIKE '%DAPTOMICINA%'
                    OR IPRDESCOR LIKE '%COLISTINA%'
                    OR IPRDESCOR LIKE 'POLIMIXINA%'
                    OR IPRDESCOR LIKE '%TIGECICLINA%'
                    OR IPRDESCOR LIKE '%DOXICICLINA%'
                    OR IPRDESCOR LIKE '%LINEZOLID%'
                    OR IPRDESCOR LIKE '%AMIKACINA%'
                    OR IPRDESCOR LIKE '%GENTAMICINA%'
                    OR IPRDESCOR LIKE '%PENICILINA G SODICA CRISTA%'
                    OR IPRDESCOR LIKE '%AMPICILINA%'
                    OR IPRCODIGO='J01CO004721' 
                    OR IPRDESCOR LIKE '%OXACILINA%'
                    OR IPRDESCOR LIKE '%CEFALEXINA%'
                    OR IPRDESCOR LIKE '%CEFAZOLINA%'
                    OR IPRDESCOR LIKE '%CEFRADINA%'
                    OR IPRDESCOR LIKE '%CEFALOTINA%'
                    OR IPRDESCOR LIKE '%CEFUROXIMA%'
                    OR IPRDESCOR LIKE '%CLINDAMICINA%'
                    OR IPRDESCOR LIKE '%FLUCONAZOL%'
                    OR IPRDESCOR LIKE '%METRONIDAZOL%'
                    )
                    --AND INNDOCUME.IDFECDOC BETWEEN '01/09/2014 00:00:00.000' AND GETDATE()
                    AND PACNUMDOC='".$paciente."' AND AINCONSEC = '".$ingre."'
                    GROUP BY INNPRODUC.OID, IPRCODIGO, IPRDESCOR, PACNUMDOC, AINCONSEC,PACPRINOM,PACSEGNOM,PACPRIAPE,PACSEGAPE,
                             antcantdias,antdosican,antdositie,antfecprim,antfecreg,entantibio.oid
                    ORDER BY IPRDESCOR";
        $res = $con->query($select);
        
        while($res2 = mssql_fetch_array($res)){
            $lista[] = array_map(utf8_encode,$res2);
        }
        
        print_r(json_encode($lista));
        $con->cerrarConexion();
    }
    
    function registroAnt(){
        session_start();
        include '../../../controlador/php/conexion/Conexion.php';
        $con = new Conexion();
        
       
        $insert = "insert into entantibio (innproduc, antcantdias, antdosican, antdositie, usu_oid, antfecprim, antfecreg, paciente)
                   values('".$this->oidAntibiotico."', '".$this->cantDias."', '".$this->cantDosis."', '".$this->canTiempo."', '".$_SESSION['usuario']."', '', GETDATE(), '".$this->paciente."')";
        $con->query($insert);
       
            
        $con->cerrarConexion();
    }
    
    function Dosis($oidAnt,$dosis,$fecha){
        
        session_start();
        include '../../../controlador/php/conexion/Conexion.php';
        $con = new Conexion();
        
        $cant = "select COUNT(*)as cant from entantifec where entantibio = '".$oidAnt."'";
        $res = $con->query($cant);
        
         while($res2 = mssql_fetch_array($res)){
            
          $n = $res2['cant'];
          
        }if($n == 0){
            
            $insert = "insert into entantifec(entantibio, antfecsumi, usu_oid)values('".$oidAnt."', GETDATE(), '".$_SESSION['usuario']."')";
            $con->query($insert);
            
            $update = "update entantibio
                        set antfecprim = '".$fecha."'
                        where oid = '".$oidAnt."'";
            $con->query($update);
            
            print_r(json_encode(array('respuesta'=>1)));
        }else{
            $insert = "insert into entantifec(entantibio, antfecsumi, usu_oid)values('".$oidAnt."', GETDATE(), '".$_SESSION['usuario']."')";
            $con->query($insert);
        }
        
        
        $con->cerrarConexion();
    }
    
    function dosisToma($dosis,$posi){
        include '../../../controlador/php/conexion/Conexion.php';
        $con = new Conexion();
        
        $count = "select COUNT(*)as n from entantifec where entantibio = '".$dosis."'";
        $res = $con->query($count);
        
        while($res2 = mssql_fetch_array($res)){
            $num = $res2['n'];
        }
        
         print_r(json_encode(array('num'=>$num,'posi'=>$posi)));
         $con->cerrarConexion();
    }
    function editarAnt($oid){
        
        include '../../../controlador/php/conexion/Conexion.php';
        $con = new Conexion();
        
        $update = "update entantibio
                   set antcantdias = '".$this->cantDias."',
                   antdosican = '".$this->cantDosis."',
                   antdositie = '".$this->canTiempo."'
                   where oid ='".$oid."'";
        $con->query($update);

        $con->cerrarConexion();
    }
}

?>
